package com.qf.listener.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *通过代码的方式创建 交换机和队列
 *
 * @version v1.0.0
 * @Description:
 * @author: 姜红凯
 * @date: 2022.03.11
 * @since 1.0
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 交换机和路由绑定
     * @return
     */
    @Bean
    public Binding binding1(@Qualifier("queue1") Queue queue , FanoutExchange fanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    @Bean
    public Binding binding2(@Qualifier("queue2") Queue queue , FanoutExchange fanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }

    @Bean
    public FanoutExchange createExchange(){
        return new FanoutExchange("boot-fanout-exchange",false,false);
    }

    @Bean("queue1")
    public Queue createQueue01(){
        //创建队列对象，并返回
        return new Queue("boot-queue1",true,false,false,null);
    }

    @Bean("queue2")
    public Queue createQueue02(){
        //创建队列对象，并返回
        return new Queue("boot-queue2",true,false,false,null);
    }

}
